#include <FastLED.h>

#define BUZZER_PIN 21
#define PASSIVE_BUZZER_PIN 23

#define CHANNEL 0    // PWM通道
#define RESOLUTION 8 // PWM占空比分辨率
#define FREQ 1000    // PWM信号频率

void setup()
{
  // 有源蜂鸣器
  pinMode(BUZZER_PIN, OUTPUT);

  // 无源蜂鸣器
  ledcSetup(CHANNEL, FREQ, RESOLUTION);
  ledcAttachPin(PASSIVE_BUZZER_PIN, CHANNEL);
}

void loop()
{
  // 有源蜂鸣器
  digitalWrite(BUZZER_PIN, 1);
  delay(2000);
  digitalWrite(BUZZER_PIN, 0);
  delay(2000);

  // 无源蜂鸣器
  ledcWriteNote(CHANNEL, NOTE_C, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_Cs, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_D, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_Eb, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_E, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_F, 5);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_Fs, 6);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_G, 7);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_Gs, 7);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_A, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_Bb, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_B, 4);
  delay(1000);
  ledcWriteNote(CHANNEL, NOTE_MAX, 4);
  delay(1000);
}
